<?php

/**
 * This is the model class for table "guestbook".
 *
 * The followings are the available columns in table 'guestbook':
 * @property integer $id
 * @property string $inquiry_timestamp
 * @property string $name
 * @property string $email
 * @property string $contact_number
 * @property string $preferred_date
 * @property string $preferred_time
 * @property integer $update
 */
class Guestbook extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Guestbook the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'guestbook';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, email, contact_number', 'required'),
			array('update', 'numerical', 'integerOnly'=>true),
			//array('email','email'),
			array('name, email, contact_number', 'length', 'max'=>45),
			array('inquiry_timestamp, preferred_date, preferred_time', 'safe'),
			//array('email', 'email'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, inquiry_timestamp, name, email, contact_number, preferred_date, preferred_time, update', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Guest ID',
			'inquiry_timestamp' => 'Inquiry Timestamp',
			'name' => 'Name',
			'email' => 'Email',
			'contact_number' => 'Contact Number',
			'preferred_date' => 'Preferred Date',
			'preferred_time' => 'Preferred Time',
			'update' => 'Update',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('inquiry_timestamp',$this->inquiry_timestamp,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('contact_number',$this->contact_number,true);
		$criteria->compare('preferred_date',$this->preferred_date,true);
		$criteria->compare('preferred_time',$this->preferred_time,true);
		$criteria->compare('update',$this->update);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}